<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>课程表页面</title>
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath}/jquery-easyui-1.8.8/themes/gray/easyui.css">
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath}/jquery-easyui-1.8.8/themes/icon.css">
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath}/jquery-easyui-1.8.8/themes/color.css">
<script type="text/javascript"
	src="${pageContext.request.contextPath}/jquery-easyui-1.8.8/jquery.min.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath}/jquery-easyui-1.8.8/jquery.easyui.min.js"></script>
</head>
<body>

	<table id="subject_dg" title="课程表管理" class="easyui-datagrid"
		style="width: 700px; height: 500px"
		url="${param.request.contextPath}/subject/list"
		toolbar="#subject_toolbar" pagination="true" rownumbers="true"
		fitColumns="true" singleSelect="true">
		<thead>
			<tr>
				<!-- field="goId"要对应实体类 -->
				<th field="subId" width="50">课程编号</th>
				<th field="subName" width="50">课程名称</th>
				<th field="tehId" width="50">课任教师编号</th>
				<th field="times" width="50">考试时间</th>
			</tr>
		</thead>
	</table>

	<!-- 工具条组件 -->
	<div id="subject_toolbar">
		<a href="javascript:void(0)" class="easyui-linkbutton"
			iconCls="icon-add" plain="true" onclick="newSubject()">新增课程</a> <a
			href="javascript:void(0)" class="easyui-linkbutton"
			iconCls="icon-edit" plain="true" onclick="editSubject()">修改课程</a> <a
			href="javascript:void(0)" class="easyui-linkbutton"
			iconCls="icon-remove" plain="true" onclick="destroySubject()">删除课程</a>
	</div>

	<!-- 新增和修改表单 start-->
	<div id="subject_dlg" class="easyui-dialog"
		style="width: 400px; height: 280px; padding: 10px 20px" closed="true"
		buttons="#subject_dlg-buttons">
		<div class="ftitle">课程表管理</div>
		<form id="subject_fm" method="post">
			<div class="fitem">
				<!-- name="admName"要和实体类名称一致 -->
				<label> 课程编号:</label> <input name="subId" class="easyui-validatebox"
					required="true">
			</div>
			<div class="fitem">
				<!-- name="admName"要和实体类名称一致 -->
				<label> 课程名称:</label> <input name="subName"
					class="easyui-validatebox" required="true">
			</div>
			<div class="fitem">
				<!-- name="admPassword"要和实体类名称一致 -->
				<label> 课任教师编号:</label> <input name="tehId"
					class="easyui-validatebox" required="true">
			</div>
			<div class="fitem">
				<!-- name="admPassword"要和实体类名称一致 -->
				<label>考试时间:</label> <input name="times" class="easyui-validatebox"
					required="true">
			</div>
		</form>
	</div>

	<div id="subject_dlg-buttons">
		<a href="#" class="easyui-linkbutton" iconCls="icon-ok"
			onclick="saveSubject()">保存</a> <a href="#" class="easyui-linkbutton"
			iconCls="icon-cancel"
			onclick="javascript:$('#subject_dlg').dialog('close')">取消</a>
	</div>

	<script type="text/javascript">

	function subjectFormatter(value,row,index){
		return row.subject.subId
		}
	function subjectFormatter(value,row,index){
		//value是传递进来的admin对象，row是当前行数据，index是第几行数据
		return row.subject.subName;
		}
	function subjectFormatter(value,row,index){
		return row.subject.times
		}
	function subjectFormatter(value,row,index){
		return row.subject.tehId
		}
		
		function newSubject() {
			$('#subject_dlg').dialog('open').dialog('setTitle', '新增课程');
			$('subject_fm').form('clear');
			url = '${param.request.contextPath}/subject/add';
		}
		function editSubject() {
			var row = $('#subject_dg').datagrid('getSelected');
			if (row) {
				$('#subject_dlg').dialog('open').dialog('setTitle', '修改课程');
				$('subject_fm').form('load', row);
				url = '${param.request.contextPath}/subject/edit?goId='
						+ row.goId;
			}
		}
		function destroySubject(){
			var row = $('#subject_dg').datagrid('getSelected');
			if(row){
				$.messager.confirm('Confirm','是否删除该课程？',function(r){
					if(r){
						$.post('${param.request.contextPath}/subject/delete',{
							goId:row.goId
							},function(result){
								if(result.success){
									$('#subject_dg').datagrid('reload');
									}else{
										$.messager.show({
											title:'提示',
											msg:result.errorMsg
											});
										}
								},'json');
						}
					});
				}
			}

		function saveSubject(){
			$('subject_fm').form('submit',{
				url:url,
				onSubmit:function(){
					return $(this).form('validate');
					},
					success : function(result){
						var result = eval('('+result+')');
						if(result.errorMsg){
							$.messager.show({
								title : '提示',
								msg : result.errorMsg
								});
							}else{
								$('subject_dlg').dialog('close');
								$('subject_dg').datagrid('reload');
								}
						}
				});
			}
	</script>


</body>
</html>